import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'widget/tabs/main_bottom_bar.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return RefreshConfiguration(
      maxOverScrollExtent: 100,
      // 头部最大可以拖动的范围,如果发生冲出视图范围区域,请设置这个属性
      footerTriggerDistance: -60,
      // 底部触发刷新的越界距离
      maxUnderScrollExtent: 100,
      // 底部最大可以拖动的范围
      enableScrollWhenRefreshCompleted: true,
      // 这个属性不兼容PageView和TabBarView,如果你特别需要TabBarView左右滑动,你需要把它设置为true
      enableLoadingWhenFailed: true,
      // 在加载失败的状态下,用户仍然可以通过手势上拉来触发加载更多
      hideFooterWhenNotFull: false,
      // Viewport不满一屏时,禁用上拉加载更多功能
      enableBallisticLoad: true,
      // 下拉 header
      headerBuilder: () => const WaterDropHeader(),
      // 上拉 footer
      footerBuilder: () => const ClassicFooter(),
      child: MaterialApp(
        title: 'Flutter MVVM Demo',
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MainBottomBar(),
        localizationsDelegates: const [
          RefreshLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate
        ],
        supportedLocales: const [
          Locale('en'),
          Locale('zh'),
          Locale('ja'),
          Locale('uk'),
          Locale('it'),
          Locale('ru'),
          Locale('fr'),
          Locale('es'),
          Locale('nl'),
          Locale('sv'),
          Locale('pt'),
          Locale('ko'),
        ],
        locale: const Locale('zh'),
        localeResolutionCallback:
            (Locale? locale, Iterable<Locale> supportedLocales) {
          debugPrint("change language");
          return locale;
        },
        builder: (BuildContext context, Widget? child) {
          return MediaQuery(
            child: child!,
            data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
          );
        },
      ),
    );
  }
}
